package zuoye;

public class NodeList {
    Node head = new Node();
    //尾部插入法
    public void insertAtTail(Student date){
        Node p = new Node();
        Node tail = head;
        p.date = (zuoye.Student) date;

        while(tail.next!=null){
            tail=tail.next;
        }

        p.next = tail.next;
        tail.next = p;
    }

    //输出
    public Student pop(){
        head=head.next;
        return head.date;
    }

    //长度
    public int length(){
        int x=0;
        for(Node node= head.next; node!=null; node=node.next){
            x++;
        }
        return x;
    }
    //逆序
    public void reverse(){
        Node first = head.next;
        for(Node node = head.next.next; node!=null; node=first.next){
            first.next = node.next;
            node.next = head.next;
            head.next = node;
        }
    }

    //比较大小
    public void insertSize(Student date){
        Node first = head;

       while (first.next!=null && first.next.date.setAge() < date.setAge()){
           first=first.next;
       }

       Node node = new Node();
       node.date = date;
       node.next = first.next;
       first.next = node;

    }

    //打印
    public void display(){
        if(head.next==null){
            System.out.println("这个表是一个空表");
            return;
        }
        for(Node node= head.next; node!=null; node=node.next){
            System.out.print(node.date +"   ");
        }
        System.out.println();
    }



}
